package com.lhz.project.system.service.base.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lhz.common.constant.DataStatusEnum;
import com.lhz.framework.security.HolderInfoManager;
import com.lhz.project.system.mapper.base.DictDataMapper;
import com.lhz.project.system.model.entity.base.DictData;
import com.lhz.project.system.model.param.base.DictDataParam;
import com.lhz.project.system.service.base.DictDataService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiHuaZhi
 * @since 2020-06-22 21:56:18
 */
@Service

public class DictDataServiceImpl extends ServiceImpl<DictDataMapper, DictData> implements DictDataService {
    @Resource
    private DictDataMapper dictDataMapper;


    @Override
    public List<DictData> selectDictDataByType(String dictType) {
        return dictDataMapper.selectDictDataByType(dictType);
    }

    @Override
    public int insert(DictDataParam param) {
        String userId = HolderInfoManager.getUserId();
        Date date = new Date();
        DictData dictData = new DictData();
        BeanUtils.copyProperties(param, dictData);

        dictData.setStatus(DataStatusEnum.VALID.getCode());
        dictData.setCreateBy(userId);
        dictData.setUpdateBy(userId);
        return dictDataMapper.insert(dictData);
    }

    @Override
    public int updateByPrimaryKey(DictDataParam param) {
        String userId = HolderInfoManager.getUserId();
        Date date = new Date();
        DictData dictData = new DictData();
        BeanUtils.copyProperties(param, dictData);

        dictData.setUpdateBy(userId);
        return dictDataMapper.updateById(dictData);
    }

    @Override
    public int deleteRealByPrimaryKey(Integer id) {
        return dictDataMapper.deleteById(id);
    }

    @Override
    public int deleteRealByPrimaryKeys(List<Integer> ids) {
        return dictDataMapper.deleteBatchIds(ids);
    }
}